<template>
  <div class="crm-page home-page">
    <div class="page-header">合同详情</div>
    <div class="page-content transparent">
      <div class="page-card">
        <div class="card-title">
          <el-button class="back-btn" size="medium" type="text" icon="el-icon-back" @click="goMainBack()">返回</el-button>
        </div>
        <div class="page-card-content">
          <div class="item-title" style="margin-top:20px">
            基本信息
          </div>
          <div class="card-item">
            <el-row :gutter="10">
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">合同名称：</span>
                <span class="content">{{ data.name }}</span>
              </el-col>
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">合同编号：</span>
                <span class="content">{{ data.number }}</span>
              </el-col>

              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">客户名：</span>
                <span class="content">  <span class="app-link" @click="gotoMainPage('customer/info',{id:data.customerId})">  {{ data.customerName }}</span></span>
              </el-col>
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">报价单：</span>
                <span class="content">  <span class="app-link" @click="gotoMainPage('quote/info',{id:data.quoteId})">  {{ data.quoteNo }}</span></span>
              </el-col>
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">合同状态：</span>
                <span class="content">{{ data.statusText }}</span>
              </el-col>
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">附件：</span>
                <span class="content">
                  <FileList :data="data.fileList||[]" />
                </span>
              </el-col>
            </el-row>
          </div>
        </div>
      </div>

      <el-row :gutter="20">
        <el-col :xs="24" :sm="24" :md="24" :lg="14" :xl="14">
          <div class="page-card">
            <div class="page-card-content">
              <div class="item-title no-border">
                <el-tabs v-model="activeTabName">
                  <el-tab-pane label="详细信息" name="1" />
                  <el-tab-pane v-if="data.status>1" label="审批流程" name="3" />
                </el-tabs>
              </div>
              <div v-if="activeTabName==='1'" class="card-item">
                <el-row :gutter="10">
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">合同编号：</span>
                    <span class="content">{{ data.number }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">所有人：</span>
                    <span class="content">{{ data.owner }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">合同名称：</span>
                    <span class="content">{{ data.name }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">开始日期：</span>
                    <span class="content">{{ formatTime( data.startDate,'YYYY-MM-DD') }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">客户名：</span>
                    <span class="content">{{ data.customerName }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">结束日期：</span>
                    <span class="content">{{ formatTime( data.endDate,'YYYY-MM-DD') }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">合同状态：</span>
                    <span class="content">
                      {{ data.statusText }}
                    </span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">付款方式：</span>
                    <span class="content">
                      {{ data.paymentModeText }}
                    </span>

                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">金额（元）：</span>
                    <span class="content">
                      {{ data.amount | moneyFormat }}
                    </span>

                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">币种：</span>
                    <span class="content">
                      {{ data.currencyText }}
                    </span>

                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">汇率：</span>
                    <span class="content">
                      {{ data.rate }}
                    </span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">税率：</span>
                    <span class="content">
                      {{ data.taxRate }}
                    </span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">开票地址：</span>
                    <span class="content">
                      <span v-for="d in data.invoiceList" :key="d.address">
                        {{ `${d.province}${d.city}${d.county}${d.address}` }} <br></span>
                    </span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">收货地址：</span>
                    <span class="content">
                      <span v-for="d in data.receiveList" :key="d.address">
                        {{ `${d.province}${d.city}${d.county}${d.address}` }}<br></span>
                    </span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">特别条款：</span>
                    <span class="content">{{ data.specialTerms }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">客户签字人：</span>
                    <span class="content">{{ data.customerSignatory }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">备注：</span>
                    <span class="content">{{ data.remark }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">客户签字人职位：</span>
                    <span class="content">{{ data.signatoryPosition }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">公司签字人：</span>
                    <span class="content">{{ data.companySignatory }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">客户签字日期：</span>
                    <span class="content">{{ formatTime( data.customerSignDate,'YYYY-MM-DD') }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">公司签字日期：</span>
                    <span class="content">{{ formatTime( data.companySignDate,'YYYY-MM-DD') }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">创建人：</span>
                    <span class="content">{{ data.createName }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">上次修改人：</span>
                    <span class="content">{{ data.updateName }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">创建时间：</span>
                    <span class="content">{{ formatTime(data.createTime) }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">上次修改时间：</span>
                    <span class="content">{{ formatTime(data.updateTime) }}</span>
                  </el-col>
                </el-row>
              </div>
              <div v-if="activeTabName==='3'" class="card-item">
                <div class="approve-status">
                  <span>状态：{{ data.statusText }}</span>
                </div>
                <ApproveProcess type="6" :ext-id="data.id" />
              </div>

            </div>
          </div>
          <QuoteCard v-if="data.id" :contract-id="data.id" :customer-id="data.customerId" :customer-name="data.customerName" :contract-no="data.number" />
          <OrderCard v-if="data.customerId" :contract-id="data.id" type="6" :customer-id="data.customerId" :contract-no="data.number" :customer-name="data.customerName" />
          <InvoiceCard v-if="data.customerId" :contract-id="data.id" :contract-no="data.number" type="6" :customer-id="data.customerId" :customer-name="data.customerName" />
          <PayCard v-if="data.customerId" :contract-id="data.id" type="6" :customer-id="data.customerId" :contract-no="data.number" :customer-name="data.customerName" />

        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="10" :xl="10">
          <ActivityCard
            :data="{
              name:data.customerName,
              relateName:data.name,
              relateId:data.id
            }"
            :type="6"
            @change="handleCardChange"
          />
          <ActivityListCard v-if="data.id" ref="listCard" :relateid="data.id" :type="6" />
        </el-col>

      </el-row>

    </div>
  </div>
</template>
<script>
import ActivityCard from '@/components/ActivityCard'
import FileList from '@/components/FileList'
import OrderCard from '@/components/InfoCard/OrderCard'
import QuoteCard from '@/components/InfoCard/QuoteCard'
import InvoiceCard from '@/components/InfoCard/InvoiceCard'
import PayCard from '@/components/InfoCard/PayCard'
import ApproveProcess from '@/components/Approve/ApproveProcess'
import ActivityListCard from '@/components/ActivityListCard'
import { getContract } from '@/api/contract'

import { getEnumText, contractStatus, currencys, payMethods } from '@/utils/enums'
import { formatTime } from '@/utils/tools'
import BigNumber from 'bignumber.js'
export default {
  name: 'CustomerInfo',
  components: { ActivityCard, ActivityListCard, FileList, OrderCard, ApproveProcess, QuoteCard, InvoiceCard, PayCard },
  data() {
    return {
      activeTabName: '1',
      data: {
        currencyText: ''

      }

    }
  },
  mounted() {
    const id = this.$route.query.id
    getContract({ id }).then(res => {
      this.data = res
      this.data.statusText = getEnumText(contractStatus, this.data.status)
      this.data.amount = BigNumber(this.data.amount).toFixed(2)
      this.data.currencyText = getEnumText(currencys, this.data.currency)
      this.paymentModeText = getEnumText(payMethods, this.data.paymentMode)
    })
  },
  methods: {
    formatTime,
    handleCardChange() {
      this.$refs.listCard.refresh()
    }

  }
}
</script>

